package com.itheima.tlias84.mapper;

import com.itheima.tlias84.dto.SelectAllDeptDTO;
import com.itheima.tlias84.entity.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeptMapper {

    @Select("select id,name,update_time from dept order by update_time desc ")
    List<SelectAllDeptDTO> selectAll();

    @Insert("insert into dept(name,create_time,update_time) values (#{d.name},#{d.createTime},#{d.updateTime})")
    int insertDept(@Param("d") Dept dept);

    @Delete("delete from dept where id=#{id}")
    int deleteById(@Param("id") Integer id);

    @Select("select id,name from dept where id=#{id}")
    SelectAllDeptDTO selectById(@Param("id") Integer id);

    @Update("update dept set name=#{d.name},update_time=#{d.updateTime} where id=#{d.id}")
    int updateDeptById(@Param("d") Dept dept);

    @Select("select id,name from dept where name=#{name}")
    Dept selectDeptByName(@Param("name") String name);

    int batchDelete(@Param("ids") List<Integer> ids);
}
